package jalgebrava.group.predicates;

import static jalgebrava.util.collections.IterableUtil.*;
import jalgebrava.group.Group;
import jalgebrava.group.groups.AllGroups;
import jalgebrava.util.F;

import org.apache.log4j.Logger;
public class GroupPredicates {
	private static Logger logger = Logger.getLogger(GroupPredicates.class);
	public static Group<?> smallestExample(F<Group<Object>, Boolean> pred) {
		for (int i : integerRange(1, Integer.MAX_VALUE)) {
			if (i % 100 == 0) {
				logger.debug("Checking " + pred + " for groups of size "
						+ i + " free = " + Runtime.getRuntime().freeMemory());
			}
			for (Group<?> g : AllGroups.allGroupsForSize(i)) {
				logger.debug("Checking " + g.getDescription());
				if (pred.apply((Group<Object>) g)) {
					return g;
				}
			}
		}
		return null;
	}

}
